package com.qingke.besuper.command.impl;

import java.util.List;

import com.qingke.besuper.app.BeSuperDAO;
import com.qingke.besuper.pojo.Answer;
import com.qingke.besuper.pojo.Question;
import com.qingke.besuper.util.BeSuperConsole;

public interface ListAnswersByQuestionId {

	public default void ListAnswersByQuestionIdCommand(int questionId) {
		BeSuperDAO dao = new BeSuperDAO();
		Question q = dao.getQuestionByQuestionId(questionId);
		List<Answer> arrA = dao.getAnswersByQuestionId(questionId);

		if (q != null) {
			int bestAnswerId = q.getBestAnswerId();
			if (bestAnswerId == -1) {
				BeSuperConsole.println("------the question of answers list------");
				for (Answer a : arrA) {
					BeSuperConsole
							.println("id:[" + a.getId() + "],answerer:[" + a.getPlayerId() + "],value:" + a.getValue());
				}
			} else {
				BeSuperConsole.println("------the best answer------");
				for (Answer a : arrA) {
					if (a.getId() == bestAnswerId)
						BeSuperConsole.println(
								"id:[" + a.getId() + "],answerer:[" + a.getPlayerId() + "],value:" + a.getValue());
				}

				BeSuperConsole.println("------the question of answers list------");
				for (Answer a : arrA) {
					if (a.getId() != bestAnswerId)
						BeSuperConsole.println(
								"id:[" + a.getId() + "],answerer:[" + a.getPlayerId() + "],value:" + a.getValue());
				}
			}
		} else {
			BeSuperConsole.println("the id of the question is not exited.");
		}
	}

}
